package com.itheima.objectStream;

import java.io.*;
import java.util.ArrayList;

public class ObjectInputStreamDemo01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //创建对象反序列化流
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("a.txt"));

        while (true){
            try {
                //readObject() 在读到没有对象之后，会抛出EOFException异常
                //抛出异常的话 用break处理，退出while循环
                Object o = ois.readObject();
                if ( o instanceof ArrayList ){
                   ArrayList<Student> arr =  (ArrayList<Student>) o ;
                    for (Student student : arr) {
                        System.out.println(student);
                    }
                }
                System.out.println(o);
            } catch (EOFException e) {
                break;
            }
        }
        ois.close();
    }
}
